import React from 'react'
import {NavBar} from 'antd-mobile'
import {Switch, Route, Redirect} from 'react-router-dom'
import NavLinkBar from '../navlink/navlink'
import Boss from '../../component/boss/boss'
import Genius from '../../component/genius/genius'
import User from '../../component/user/user'
import Msg from '../../component/msg/Msg'
import {getChatMsgList, ReceveMsg} from '../../redux/chat.redux'
import {connect} from 'react-redux'
import './dashboard.css'

@connect(
    state => state,
    {getChatMsgList, ReceveMsg}
)
class Dashboard extends React.Component {
    componentDidMount() {
        this.props.getChatMsgList();
        this.props.ReceveMsg();
    }

    render() {
        let {pathname} = this.props.location
        const user = this.props.user
        if (pathname == "/") {
            pathname = "/" + user.type
        }
        const navList = [
            {
                path: '/boss',
                text: '牛人',
                icon: 'boss',
                title: '牛人列表',
                component: Boss,
                hide: user.type == 'genius'
            },
            {
                path: '/genius',
                text: 'boss',
                icon: 'job',
                title: 'BOSS列表',
                component: Genius,
                hide: user.type == 'boss'
            },
            {
                path: '/msg',
                text: '消息',
                icon: 'msg',
                title: '消息列表',
                component: Msg
            },
            {
                path: '/me',
                text: '我',
                icon: 'user',
                title: '个人中心',
                component: User
            }
        ]
        return (
            <div className="dashBoard">
                <NavBar className='fixd-header' mode='dard'>{
                    navList.find(v => v.path == pathname) ? navList.find(v => v.path == pathname).title :
                        // navList.find(v=>v.path=="/"+this.props.user.type).title
                        ""}
                </NavBar>
                <div className="databoard-container">
                    <Switch>
                        {navList.map(v => (
                            <Route key={v.path} path={v.path} component={v.component}></Route>
                        ))}
                        <Redirect from="/" to={
                            navList.find(v => v.path == pathname) ? navList.find(v => v.path == pathname).path : "/"
                        }></Redirect>
                    </Switch>
                </div>
                <NavLinkBar data={navList}></NavLinkBar>
            </div>
        )
    }
}
export default Dashboard
